﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Swaf.Container;

namespace Calendars
{
	public class CalendarAssist
	{
		public static string calcDisplayName(DateTime startDate, DateTime endDate, bool allDayEvent, bool alwaysIncludeDate)
		{
			string disp = "";
			if (startDate.Date == endDate.Date)
			{
				if (!allDayEvent)
				{
					if (startDate.TimeOfDay == endDate.TimeOfDay)
						disp = startDate.ToShortTimeString();
					else if (!alwaysIncludeDate)
						disp = string.Format("{0} - {1}", startDate.ToShortTimeString(), endDate.ToShortTimeString());
					else
						disp = string.Format("{0} {1} - {2}", DateFormattingNode.FormatDate(startDate, "easyDateOnly", true), startDate.ToShortTimeString(), endDate.ToShortTimeString());
				}
				else
					disp = DateFormattingNode.FormatDate(startDate, "easyDateOnly", true);
			}
			else
			{
				TimeSpan ts = endDate.Date - startDate.Date;
				string dd = ts.Days == 1 ? "day" : "days";
				if(!allDayEvent)
					disp = string.Format("{0} {1}, {2} {3} till {4} {5}", ts.Days, dd, startDate.ToString("M/d"), startDate.ToShortTimeString(), endDate.ToString("M/d"), endDate.ToShortTimeString());
				else
					disp = string.Format("{0} {1}, {2} till {3}", ts.Days, dd, startDate.ToString("M/d"), endDate.ToString("M/d"));
			}

			return disp;
		}
	}
}
